package com.kk.xhr.model.assembler;

import com.kk.xhr.common.pojo.TrainStatusEnum;
import com.kk.xhr.model.dto.TrainDTO;
import com.kk.xhr.model.entity.EmployeeTrain;
import org.mapstruct.Mapper;
import org.mapstruct.factory.Mappers;

/**
 * 培训转换工具类
 *
 * @author kkmystery
 * @version 1.0 2021/2/28 11:31
 * @since 1.0.0
 */
@Mapper(componentModel = "spring")
public interface TrainStructKit {

    TrainStructKit INSTANCE = Mappers.getMapper(TrainStructKit.class);

    /**
     * dto -> entity
     *
     * @param dto dto
     * @return entity
     */
    EmployeeTrain toEntity(TrainDTO dto);

    /**
     * entity -> dto
     *
     * @param entity entity
     * @return dto
     */
    TrainDTO toDto(EmployeeTrain entity);

    /**
     * TrainStatusEnum类型 byte -> enum
     *
     * @param status 状态
     * @return TrainStatusEnum
     */
    default TrainStatusEnum statusConvertor(Byte status) {
        if (null == status) {
            return null;
        }
        return TrainStatusEnum.from(status);
    }

    /**
     * TrainStatusEnum类型 enum -> byte
     *
     * @param status 状态
     * @return byte
     */
    default Byte statusConvertor(TrainStatusEnum status) {
        if (null == status) {
            return null;
        }
        return status.getValue();
    }
}
